package com.seckill.controller.admin;

import com.seckill.pojo.entity.SeckillProduct;
import com.seckill.service.SeckillProductService;

import com.sky.result.PageResult;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀特价农产品管理接口
 */
@RestController
@RequestMapping("/admin/seckill/product")
@Tag(name = "秒杀特价农产品管理接口", description = "秒杀特价农产品管理接口")
@Slf4j
public class SeckillProductController {

    @Autowired
    private SeckillProductService seckillProductService;

    /**
     * 新增秒杀特价农产品
     * @param seckillProduct
     * @return
     */
    @PostMapping
    //@ApiOperation("新增秒杀特价农产品")
    public Result<String> save(@RequestBody SeckillProduct seckillProduct) {
        log.info("新增秒杀特价农产品：{}", seckillProduct);
        seckillProductService.save(seckillProduct);
        return Result.success();
    }

    /**
     * 分页查询秒杀特价农产品
     * @param page
     * @param pageSize
     * @param activityId
     * @return
     */
    @GetMapping("/page")
    //@ApiOperation("分页查询秒杀特价农产品")
    public Result<PageResult> page(int page, int pageSize, Long activityId) {
        log.info("分页查询秒杀特价农产品：第{}页，每页{}条，活动ID：{}", page, pageSize, activityId);
        PageResult pageResult = seckillProductService.pageQuery(page, pageSize, activityId);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询秒杀特价农产品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    //@ApiOperation("根据id查询秒杀特价农产品")
    public Result<SeckillProduct> getById(@PathVariable Long id) {
        log.info("根据id查询秒杀特价农产品：{}", id);
        SeckillProduct seckillProduct = seckillProductService.getById(id);
        return Result.success(seckillProduct);
    }

    /**
     * 修改秒杀特价农产品
     * @param seckillProduct
     * @return
     */
    @PutMapping
    //@ApiOperation("修改秒杀特价农产品")
    public Result<String> update(@RequestBody SeckillProduct seckillProduct) {
        log.info("修改秒杀特价农产品：{}", seckillProduct);
        seckillProductService.update(seckillProduct);
        return Result.success();
    }

    /**
     * 删除秒杀特价农产品
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    //@ApiOperation("删除秒杀特价农产品")
    public Result<String> delete(@PathVariable Long id) {
        log.info("删除秒杀特价农产品：{}", id);
        seckillProductService.delete(id);
        return Result.success();
    }
}